//引入express框架
const express = require('express');

//创建模块化路由
const admin = express.Router();

//渲染登录页面
admin.get('/login', require('./admin/loginPage.js'));

//实现登录功能
admin.post('/login', require('./admin/login.js'));

//渲染用户界面 
admin.get('/user', require('./admin/userPage.js'));

//实现退出功能
admin.get('/logout', require('./admin/logout.js'));

//实现用户编辑功能
admin.get('/user-edit', require('./admin/user-edit.js'));

//实现用户数据提交功能
admin.post('/user-edit', require('./admin/user-edit-fn.js'));

//实现用户修改功能
admin.post('/user-modify', require('./admin/user-modify.js'));

//删除用户功能
admin.get('/user-delete', require('./admin/user-delete.js'));

//添加文章路由
admin.get('/article', require('./admin/article.js'));

//文章编辑路由
admin.get('/article-edit', require('./admin/article-edit.js'));

//文章添加路由
admin.post('/article-add', require('./admin/article-add.js'));

//文章修改路由
admin.post('/article-modify',require('./admin/article-modify.js'));

//文章删除路由
admin.get('/article-delete',require('./admin/article-delete.js'));

//实现退出功能
admin.get('/logout', (req, res) => {
	//删除session
	req.session.destory(function () {
		//删除cookie
		res.clearCookie('connect.sid');
		//重定向到登录页面
		res.redirect('/admin/login')
	})
})
module.exports = admin;